const config = require('../../common/config');

Page({
    data:{
        issueContent:'',
        issueContentLength : 0,
        mobile:''
    },
    onLoad:function (opt) {
        wx.setNavigationBarTitle({
            title: '反馈'
        })
    },
    changeIssueContent:function (e) {
        var issueContent = e.detail.value;
        if(issueContent.length<=200){
            this.setData({
                issueContent : issueContent,
                issueContentLength : issueContent.length
            })
        }

    },
    changeLinkMobile:function (e) {
        this.setData({
            mobile : e.detail.value
        })
    },
    submitForm:function () {
        var _this = this;

        if(_this.data.issueContent.trim() == ''){
            return;
        }

        wx.showLoading({
            title: '提交中..',
            icon: 'loading',
            duration: config.TIME_OUT,
            mask:true
        })

        wx.request({
            url: config.COMMPT_REQPATH,
            header: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            method:'POST',
            data: {
                accessToken: '',
                refreshToken: '',
                serviceName: 'issueService',
                methodName: 'saveIssueInfo',
                reqData:JSON.stringify({
                    issueContent:_this.data.issueContent,
                    mobile:_this.data.mobile,
                    userId:wx.getStorageSync(config.USER_ID),
                    platformId:'101'
                })
            },
            success: function (res) {
                var resultData = res.data;
                wx.hideLoading();
                if(resultData.code == 1){
                    _this.setData({
                        issueContent : '',
                        issueContentLength : 0
                    })

                    wx.navigateBack({
                        delta: 1
                    })
                }else{
                    common.consoleLog('issue保存反馈信息失败：');
                    common.consoleLog(resultData);
                }
            },
            fail:function (e) {
                wx.hideLoading();
                common.consoleLog(e.errMsg);
            }
        })

    }
})